<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目编号" prop="code">
        <el-input v-model="queryParams.code" placeholder="请输入项目编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="项目名称" prop="name" label-width="120px">
        <el-input v-model="queryParams.name" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="项目阶段" prop="status" label-width="120px">
        <!-- <el-input v-model="queryParams.status" placeholder="请输入项目阶段" clearable @keyup.enter.native="handleQuery" /> -->
        <el-select v-model="queryParams.status" placeholder="项目阶段" clearable style="width: 240px">
          <el-option v-for="i in statusOptions" :key="i.id" :label="i.fullName" :value="i.id" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <!-- v-hasPermi="['manager:building:add']" -->
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="buildingList" @selection-change="handleSelectionChange">
      <el-table-column label="项目编号" align="center" prop="code" />
      <el-table-column label="合同名称" align="center" prop="name" />
      <el-table-column label="金额" align="center">
        <template slot-scope="scope">
          {{ scope.row.amountType == 1 ? scope.row.totalAmount : scope.row.perSquareMeterTotalAmount }}
        </template>
      </el-table-column>
      <el-table-column label="项目阶段" align="center" prop="status">
        <template slot-scope="scope">
          {{ scope.row.status | dynamicText(statusOptions) }}
        </template>
      </el-table-column>
      <el-table-column label="驳回原因" align="center" prop="reasonForRefusal">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" placement="top-start">
            <div slot="content" style="width:10rem">{{ scope.row.reasonForRefusal }}</div>
            <span class="ellipsisList">{{ scope.row.reasonForRefusal }}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="终止原因" align="center" prop="cancelReason">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" placement="top">
            <div slot="content" style="width:10rem">{{ scope.row.cancelReason }}</div>
            <span class="ellipsisList">{{ scope.row.cancelReason }}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="立项时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- v-hasPermi="['manager:building:remove']" -->
          <el-button size="mini" type="text" @click="handleDetail(scope.row)">查看详情</el-button>
          <!-- <el-button size="mini" type="text" @click="handleEditFloor(scope.row.id)"
            v-hasPermi="['manager:building:remove']">查看任务</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <addContract v-if="addContractVisible" ref="addContract" @refreshAddContract="refreshAddContract" />
  </div>
</template>
<script>
import { listContract } from "@/api/contract/contractOrg";
import addContract from "./addContract.vue";
export default {
  name: "Building",
  components: { addContract },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 委托单位列表
      userList: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 建筑表格数据
      buildingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 详情页面
      addContractVisible: false,
      // 编辑楼层
      editFloorVisible: false,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        code: null,
        status: null
      },
      // 表单参数
      form: {},
      statusOptions: [
        { id: 1, fullName: '选择委托单位' },
        { id: 2, fullName: '项目信息' },
        { id: 3, fullName: '清单录入' },
        { id: 4, fullName: '合同确认' },
        { id: 5, fullName: '委托单位签章' },
        { id: 6, fullName: '方案推送' },
        { id: 7, fullName: '付款与上传' },
        { id: 8, fullName: '支付记录' },
        { id: 9, fullName: '文件归档' },
        { id: 10, fullName: '委托单位驳回' },
        { id: 11, fullName: '项目终止' }
      ],

    };
  },
  created() {
    this.getList();
  },
  mounted() { },
  methods: {
    /** 查询建筑列表 */
    getList() {
      this.loading = true;
      listContract(this.queryParams).then((response) => {
        this.buildingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        serviceOrgId: null,
        customerId: null,
        name: null,
        address: null,
        pointPositionDesc: null,
        abovegroundNumber: null,
        undergroundNumber: null,
        longitude: null,
        latitude: null,
        invalid: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    // 编辑楼层
    handleEditFloor(id) {
      this.editFloorVisible = true;
      this.$nextTick(() => {
        this.$refs.Detail.init(id);
      });
    },

    // 跳转详情
    handleDetail(row) {
      this.addContractVisible = true;
      this.$nextTick(() => {
        this.$refs.addContract.init(row.id);
      });
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.addContractVisible = true;
      this.$nextTick(() => {
        this.$refs.addContract.init();
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBuilding(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改建筑";
      });
    },

    // 刷新页面
    refreshAddContract() {
      this.addContractVisible = false;
      this.$nextTick(() => {
        this.getList();
      });

    }
  },
};
</script>

<style lang="scss" scoped>
.ellipsisList {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  /* 控制最多显示3行文字 */
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
